package cn.fabrice.exception;

import cn.fabrice.common.BaseResponse;
import cn.fabrice.common.ErrorCode;
import jdk.nashorn.internal.runtime.RewriteException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public BaseResponse businessExceptionHandler(BusinessException e){
        log.error("BusinessException"+e.getMessage());
        return BaseResponse.error(e.getCode(), e.getMsg(), e.getDescription());
    }
    @ExceptionHandler(RuntimeException.class)
    public BaseResponse runtimeExceptionHandler(RuntimeException e){
        log.error("RuntimeException，{}",e);
        return BaseResponse.error(ErrorCode.SYSTEM_ERROR);
    }
}
